<%@ page contentType="text/html;charset=UTF-8" isErrorPage="true"%>
<%@ include file="/comm/include.jsp"%>
<script type="text/javascript">
$(function(){
	$('#data').datagrid({  
	    url:'${ctx}/advert/list.htm',
	    pagination:true,
	    checkOnSelect:false,
	    singleSelect:true,
	    idField:'id',
	    nowrap:true,
	    rownumbers:true,
	    onClickRow: function(rowIndex,rowData){
	    	$("#preImg").attr("src","${ctx}/files/"+rowData.img);
              	var top = 0;
	  	    	var right = 0;
	  	    	$("#imgDiv").css({'right':right+'px','top':top+'px'}).hide().fadeIn('fast');
		},
	    columns:[[
	        {field:'title',title:'推荐名称',width:150},
	        {field:'content',title:'内容',width:350},
	        {field:'link',title:'超链接'},
	        {field:'img',title:'图片地址'},
	        {field:'createTime',title:'创建时间',width:100}
	    ]],
	    toolbar:"#tb"
	});
	
	$("#btnAdd").click(function(){
		window.location.href="${ctx}/advert/add.htm";
	});
	$("#btnEdit").click(function(){
		var row = $('#data').datagrid('getSelected');
        if (row){
			window.location.href= "${ctx}/advert/edit.htm?id=" + row.id;
        }
	});
	$("#btnRemove").click(function(){
		var row = $('#data').datagrid('getSelected');
        if (row){
        	$.post('${ctx}/advert/remove.htm?id='+row.id,function(data){
    			if(data==1) {
    				$('#data').datagrid('reload');
    			}else {
    				alert('删除失败');
    			}
    		},"text");
        }
	});
});
</script>
<div>
	<table id="data"></table>
	<div id="tb" style="padding:5px;height:auto">
		<div>
			<a href="javascript:;" id="btnAdd" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加推荐</a> 
			<a href="javascript:;" id="btnEdit" class="easyui-linkbutton" iconCls="icon-edit-sn" plain="true">修改推荐</a> 
			<a href="javascript:;" id="btnRemove" class="easyui-linkbutton" iconCls="icon-del-sn" plain="true">删除推荐</a> 
		</div>
	</div>
     <div id="imgDiv" style="display:none;z-index:99;position: absolute;">
		<img id="preImg">
	</div>
</div>


